< previous page page_275 next page >

Page 275
To ensure that the mouse pointer does not burn the phosphors, hide the pointer. You can do this with the ShowCursor API function.
Next, create whatever animation you want to run during the screen saver. You can use bouncing balls, revolving planets, sliding bitmaps, or whatever you like. The only requirement is that you do not allow an image to remain in one place for very long.
To allow the user to stop the screen saver, add code that exits your program in all MouseMove, MouseDown, and KeyDown event handlers. Unfortunately, Visual Basic sometimes generates a few spurious MouseMove events as soon as a screen saver starts. It also generates a MouseMove event once in a while when the mouse has not actually moved.
To prevent the screen saver from exiting when it receives these "false" events, see if the mouse has moved more than a few pixels. If the mouse has not moved much, ignore the event.
e10a6a0a59f035e870d90cca05b85fce.gif
Private Sub Form_MouseMove(Button As Integer, _
    Shift As Integer, X As Single, Y As Single)
Static x0 As Integer
Static y0 As Integer

    ' Do nothing except in screen saver mode.
    If RunMode <> rmScreenSaver Then Exit Sub

    ' Unload on large mouse movements.
    If ((x0 = 0) And (y0 = 0)) Or _
        ((Abs(x0 - X) < 5) And (Abs(y0 - Y) < 5)) _
        Then
            ' It's a small movement.
            x0 = X
            y0 = Y
            Exit Sub
    End If

    ' This is a big movement. Stop the screen saver.
    Unload Me
End Sub
Windows may start a screen saver when another copy of it is already running. The program should check App.PrevInstance and exit if another instance is running.
Once you have tested and debugged your program, you are ready to turn it into an executable screen saver. In the Visual Basic development environment, select the File menu's Make EXE File command. In the File name box, specify a .scr extension instead of the usual .exe. Then click on the Options button and add the string "SCRNSAVE:" at the front of the application's title. For example, to create a screen saver named Bounce, set the title to "SCRNSAVE:Bounce." Create the executable and then move it into your Windows directory. You now have a working screen saver.

 
< previous page page_275 next page >